package com.cc.service;

import com.cc.mapper.EbUserMapper;
import com.cc.model.EbUser;
import com.cc.model.EbUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2020-10-30 14:26
 */
@Service
public class UserService {
    @Autowired
    private EbUserMapper ebUserMapper;

    public EbUser findByUsernameAndPwd(String username,String password){
        //1.构建高级查询的exmpale对象
        EbUserExample example = new EbUserExample();
        //2.根据example对象构建查询条件对象
        EbUserExample.Criteria criteria = example.createCriteria();
        //3.将条件设置到criteria对象上
        criteria.andEuUserNameEqualTo(username)
                .andEuPasswordEqualTo(password);
        //4.根据example调用查询按条件查询

        List<EbUser> lgnUser = ebUserMapper.selectByExample(example);
        if(lgnUser.size()>0){
            return lgnUser.get(0);
        }
        return null;
    }

    /**
     * 添加用户的方法
     * @param ebUser
     * @return
     */
    public int save(EbUser ebUser) {
        return  ebUserMapper.insertSelective(ebUser);
    }
}
